package com.ea.eadp.nexus.test.pageDefinition.newconsole;

import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.testng.Assert;


public class SecurityQuestionPage extends ConsoleBasePage {
    public final static String answerInputBox = "securityAnswer";

    public SecurityQuestionPage(WebDriver driver) {
        super(driver, SecurityQuestionPage.class, answerInputBox);
    }

    public void selectQuestion(int index) {
        log.info("Select Security Question: " + index);
        sendControllerKey('A');
        if (index >= 0) {
            for (int i = 0; i < index; i++) {
                sendControllerKey(Keys.DOWN);
            }
        } else {
            for (int i = 0; i > index; i--) {
                sendControllerKey(Keys.UP);
            }
        }
        sendControllerKey('A');
    }

    public void enterSecurityAnswer(String answer) {
        log.info("Enter Security Answer:" + answer);
        sendInput(answerInputBox, answer);
        clickBlank("//div[@id='panel-security-question']//span[@class='title']");
        sendControllerKey('A');
    }

    public void validateSecurityAnswer(String answer, String errorMessage) {
        log.info("Validate Security Answer:" + answer);
        sendInput(answerInputBox, answer);
        clickBlank("//div[@id='panel-security-question']//span[@class='title']");
        Assert.assertEquals(getAnswerInvalidError(), errorMessage, "Input not trigger the correct error message");
    }

    public String getTitle() {
        return getElementStringByXPath("//div[@id='panel-security-question']//span[@class='title']");
    }

    public String getDescription() {
        return getElementStringByXPath("//div[@id='panel-security-question']//p[@class='description']");
    }

    public String getQaLabel() {
        return getElementStringByXPath("//div[@id='panel-security-question']//li[1]/span[@class='title']");
    }

    public String getQaList() {
        return getElementStringByXPath("//div[@id='securityqa']//span");
    }

    public String getAnswerLabel() {
        return getElementStringByXPath("//li[@id='securityAnswerItem']//label[@class='origin-ux-textbox-label']");
    }

    public String getAnswerInvalidError() {
        return getElementStringByXPath("//li[@id='securityAnswerItem']//span[@class='origin-ux-textbox-status-message origin-ux-status-message']");
    }
}